"""
======================
@author:SUNLIN
@time:2025/3/5 19:08
@email:1232@163.com
@description: 获取单个页面的信息
======================
"""
import requests
from bs4 import BeautifulSoup


##
def get_list(soup_list):
    list = []
    for ele in soup_list:
        list.append(ele.string)
    return list


# 访问网页、获取信息
url = 'https://movie.douban.com/subject/1292064/'
headers = {'user-agent': 'my-app/0.0.1'}
response = requests.get(url=url, headers=headers)
# 获取目标信息
soup = BeautifulSoup(response.text, 'html.parser')

# 存储容器，电影信息预览
movie_info = {}
# 电影名称
movie_info['movie_name'] = soup.find(property="v:itemreviewed").text
movie_info['director'] = soup.find(rel="v:directedBy").string
movie_info['writer'] = soup.find_all(class_="attrs")[1].string
movie_info['actor_list'] = get_list(soup.find_all(rel="v:starring"))
movie_info['type_list'] = get_list(soup.find_all(property="v:genre"))
movie_info['language'] = soup.find(string='语言:').next_element  # 获取当前元素的下一个元素
movie_info['release_date'] = soup.find(property="v:initialReleaseDate").string
movie_info['run_time'] = soup.find(property="v:runtime").string
movie_info['average_score'] = soup.find(property="v:average").string
movie_info['number_of_people'] = soup.find(property="v:votes").string

for key in movie_info:
    print(key, ':', movie_info.get(key))
